var i=0;
//var length = $("#main>div").length-2;

$(document).ready(function(){
	var length = $("#main>div").length-1;
	for(var j=length;j>=1;j--){
		$("#nav").prepend('<input type="button" value="'+j+'" class="true" />');
	}
});

$(function(){
	$('#nav>input').click(function(){
		if(i=='0'){
			i=1;
		}
		var b = parseInt(this.value);
		//alert(b);
		if(b>i){
			for(var j = i;j<b;j++){
				$($("#main>div")[j]).hide("slow");
			}
			i=b-1;
		}else if(b<i){
			
			for(var j = i;j>=b;j--){
				$($("#main>div")[j-1]).show("slow");
			}
			i=b-1;
		}else if(b=i){
			last();
		}
	});
});

function next(){
	i++;
	if($("#main>div").length-2 < i){
		i = $("#main>div").length-2;
	}
	//alert(i);
	$($("#main>div")[i]).hide("slow");
}

function last(){
	i--;
	if(i<0){
		i=0;
	}
	//alert(i);
	$($("#main>div")[i+1]).slideDown("slow");
}

function keyUp(e){
	var currKey=0,e=e||event;
	currKey=e.keyCode||e.which||e.charCode;
	var keyName = String.fromCharCode(currKey);
    //alert("按键码: " + currKey);
	if(currKey=="39"){
		next();
	}else if(currKey=="37"){
		last();
	}
}
document.onkeyup=keyUp;
